﻿using System;
using Communication.Message.Util;

namespace Communication.Message.FpgaUpdate
{
	// Token: 0x02000025 RID: 37
	public class SendCheckSumMessage : FlashUpdateChannelMessage
	{
		// Token: 0x06000141 RID: 321 RVA: 0x00003830 File Offset: 0x00001A30
		public SendCheckSumMessage(byte desId, short checkSum, int totalRecTimeoutMillis, int spaceRecTimeoutMillis, int sendTimeoutMillis) : base(desId, 6, new byte[]
		{
			(byte)(checkSum >> 8 & 255),
			(byte)(checkSum & 255)
		}, 2, 0, totalRecTimeoutMillis, spaceRecTimeoutMillis, sendTimeoutMillis)
		{
		}

		// Token: 0x06000142 RID: 322 RVA: 0x0000386C File Offset: 0x00001A6C
		public void SetPayload(short checkSum)
		{
			base.SetPayload(new byte[]
			{
				(byte)(checkSum >> 8 & 255),
				(byte)(checkSum & 255)
			}, 0, 2);
		}

		// Token: 0x06000143 RID: 323 RVA: 0x000038A4 File Offset: 0x00001AA4
		protected override bool DealwithReceiveMsg()
		{
			if (!base.IdentifyFrame())
			{
				return false;
			}
			int num = this.receiveBuffer.ReaderIndex();
			int @ushort = (int)this.receiveBuffer.GetUshort(num + 3);
			short @short = this.receiveBuffer.GetShort(num + 5 + @ushort);
			short num2 = CrcUtil.Crc16(this.receiveBuffer.Array(), this.receiveBuffer.ReaderIndex(), 5 + @ushort, CrcType.High_Low);
			if (@short != num2)
			{
				this.SetFailure(new CrcRrrorException());
				return true;
			}
			if (Enum.IsDefined(typeof(FlashUpdateErrorCode), (uint)this.receiveBuffer.GetByte(num + 5)))
			{
				FlashUpdateErrorCode errorCode = (FlashUpdateErrorCode)Enum.Parse(typeof(FlashUpdateErrorCode), this.receiveBuffer.GetByte(num + 5).ToString());
				this.errorCode = errorCode;
				base.SetSuccess();
				return true;
			}
			this.SetFailure(new IllegalErrorCodeException());
			return true;
		}
	}
}
